home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: December 9, 1996
- // Author: DSW
- //
- // Description:
- // pv_performAction, used currently used by Project Viewer and multilister.
- // callback Performs standard file operations such as Open, Save, Import, etc.
- //
-
- proc string pv_basename(string $fileName)
- //
- // Description:
- // Given a file name, return the basename.
- //
- {
- string $fName = $fileName;
- if (`about -nt`) {
- $fName = convert($fName);
- }
-
- string $buffer[];
- int $nTokens;
- $nTokens = `tokenize $fName "/" $buffer`;
-
- if ($nTokens > 0) {
- $fName = $buffer[$nTokens-1];
- }
-
- $nTokens = `tokenize $fName "." $buffer`;
- if ($nTokens > 0) {
- $fName = $buffer[0];
- }
-
- return $fName;
- }
-
- global proc int pv_performAction ( string $theFile, string $fileType )
- //
- // Description:
- // get the file name from the finder and use it to perform the
- // desired action.
- //
- {
- global string $gv_operationMode;
- global string $gFileOptionsString;
- global string $gReplaceReferenceNode;
-
- string $theFinder;
- string $activeWS;
- int $index;
- string $optionsScript;
- int $OKToSave;
- string $result;
- int $fileExists;
- string $cmdString;
- string $translatorOptions;
- int $status = false;
-
- string $currentDir = `workspace -q -dir`;
- retainWorkingDirectory $currentDir;
-
- int $win32 = `about -nt`;
- int $macOS = `about -mac`;
-
- if ($theFile != "")
- {
- $fileExists = `file -q -ex $theFile`;
-
- if ($fileType == "Best Guess")
- {
- // We need to determine the type.
-
- if ($gv_operationMode == "SaveAs")
- {
- if (`optionVar -exists defaultFileSaveType`)
- {
- $fileType = `optionVar -q defaultFileSaveType`;
- }
- else
- {
- $fileType = "mayaBinary";
- }
- }
- else if ($gv_operationMode == "ExportAll")
- {
- if (`optionVar -exists defaultFileExportAllType`)
- {
- $fileType = `optionVar -q defaultFileExportAllType`;
- }
- else
- {
- $fileType = "mayaBinary";
- }
- }
- else if ($gv_operationMode == "ExportActive")
- {
- if (`optionVar -exists defaultFileExportActiveType`)
- {
- $fileType = `optionVar -q defaultFileExportActiveType`;
- }
- else
- {
- $fileType = "mayaBinary";
- }
- }
- else
- {
- if ($fileExists)
- {
- // We must be reading a file. Get the actual type.
-
- string $fileTypeList[];
- $fileTypeList = `file -q -typ $theFile`;
-
- int $listSize = size($fileTypeList);
- int $index;
- for ($index = 0; $index < $listSize; $index++)
- {
- if (`translator -q -rs $fileTypeList[$index]`)
- {
- $fileType = $fileTypeList[$index];
- break;
- }
- }
-
- // If we got here we had a problem... let's see if we
- // can't sort it out for the users.
-
- // Is the file readable?
- string $fullPath = `workspace -en $theFile`;
- if ( filetest("-r",$fullPath) == 0 )
- {
- string $errMsg = "Cannot open " + $fullPath +
- ": Permission denied";
- confirmDialog -m $errMsg
- -b "Cancel" -db "Cancel"
- -parent projectViewerWindow;
- return $status;
- }
-
- // If the file is readable, we just must not understand it.
-
- if ($fileType == "Best Guess")
- {
- // Get the file extension. Be sure to remove case to
- // simplify comparisons.
- //
- string $extension = `match "\\..*$" $theFile`;
- $extension = `tolower $extension`;
-
- int $postedDialog = false;
-
- if (`about -evalVersion`) {
- //
- // Maya Personal Learning Edition.
- //
- if ( $extension == ".ma" || $extension == ".mb" ) {
- confirmDialog -message "Files created by Maya cannot be opened by Maya Personal Learning Edition."
- -button "Cancel" -defaultButton "Cancel"
- -parent projectViewerWindow;
- $postedDialog = true;
- }
- } else {
- //
- // Maya.
- //
- if ( $extension == ".mp" ) {
- confirmDialog -message "Files created by Maya Personal Learning Edition cannot be opened by Maya."
- -button "Cancel" -defaultButton "Cancel"
- -parent projectViewerWindow;
- $postedDialog = true;
- }
- }
-
- if (!$postedDialog) {
- confirmDialog -message "Unrecognized File Type"
- -button "Cancel" -defaultButton "Cancel"
- -parent projectViewerWindow;
- }
-
- return $status;
- }
- }
- }
- }
-
-
- $translatorOptions = ($fileType+"Options");
- if (`optionVar -exists $translatorOptions`) {
- // Post the new options.
- $gFileOptionsString = `optionVar -q $translatorOptions`;
- } else {
- $gFileOptionsString = "";
- }
-
-
- if ($gv_operationMode == "SaveAs"
- || $gv_operationMode == "ExportAll"
- || $gv_operationMode == "ExportActive") {
-
- // We first check to see if the given file has an extension
- // If it does and this does not match the given type, we change
- // the type to be that specified in the extension.
- if ( $fileType == "mayaAscii" || $fileType == "mayaBinary" )
- {
- string $extension = `match "\\..*$" $theFile`;
- $extension = `tolower $extension`;
- if ( $extension == ".ma" && $fileType == "mayaBinary" )
- $fileType = "mayaAscii";
- else if ( $extension == ".mb" && $fileType == "mayaAscii" )
- $fileType = "mayaBinary";
- }
-
- // See if we are overwriting a file. The NT file browser
- // has already performed this check.
- //
- $OKToSave = 1;
- if (!$win32 && !$macOS)
- {
- // If we are using default extensions, then we need to
- // do some special case checking
- //
- if (`file -q -de`) {
- string $oldType[] = `file -q -type`;
-
- // Turn default extensions off or changing the
- // type changes the name
- //
- file -de 0;
-
- // Set the appropriate type
- //
- file -type $fileType;
-
- // If both -de and -ex are specified, check for
- // the existence of the file with the default
- // extension applied.
- //
- $fileExists = `file -q -de -ex $theFile`;
-
- // Restore the original type
- //
- file -type $oldType[0];
-
- // Restore the default extensions
- //
- file -de 1;
- }
-
- if ($fileExists && $gv_operationMode == "SaveAs") {
- $result = `confirmDialog -m "File Exists. Overwrite?"
- -b "Yes" -b "Cancel" -db "Cancel"
- -parent projectViewerWindow`;
- if ($result == "Yes") {
- $OKToSave = 1;
- } else $OKToSave = 0;
- }
- }
-
- if ($OKToSave) {
- // Get the icon.
- if ( $gv_operationMode == "SaveAs" )
- {
- file -rename $theFile; // Rename the file.
- if (`saveImage -ex fo_saveIcon`) {
- // This should probably be passed in somehow.
- saveImage -e -sf $theFile fo_saveIcon; // Get the save Icon.
- optionVar -sv defaultFileSaveType $fileType;
- }
-
- string $cmd;
- if ($gFileOptionsString == "") {
- $cmd = "file -f -save -type \""+$fileType+"\"";
- } else {
- $cmd = "file -f -save -options \""+$gFileOptionsString+"\" -type \""+$fileType+"\"";
- }
- evalEcho($cmd);
- // We want the full name as maya knows it for
- // recent files
- string $theSavedFile = `file -q -sn`;
- if ( `about -nt` )
- $theSavedFile = convert( $theSavedFile );
- addRecentFile ($theSavedFile, $fileType);
- } else if ($gv_operationMode == "ExportActive") {
- // Set up the export parameters.
- if (`optionVar -ex exportIncludeInputs`) {
- if (`optionVar -q exportIncludeInputs`) {
- file -chn `optionVar -q exportIncludeChannels`;
- file -ch `optionVar -q exportIncludeHistory`;
- file -exp `optionVar -q exportIncludeExpressions`;
- file -con `optionVar -q exportIncludeConstraints`;
- } else {
- file -chn false;
- file -ch false;
- file -exp false;
- file -con false;
- }
- } // Else don't change the default values.
-
- // If the file type is an animation type, then
- // set the channels value to true. Animation
- // exporters should set an int optionVar in the
- // export options script. The optionVar should be
- // set true to always export animation.
- //
- string $isAnimOptVar = ($fileType+"AnimationFile");
- float $channelsValueChanged = false;
- float $oldChannelsValue = `file -q -chn`;
-
- if (`optionVar -ex $isAnimOptVar` &&
- `optionVar -q $isAnimOptVar`) {
- file -chn true;
- $channelsValueChanged = true;
- }
-
- if (`optionVar -ex exportIncludeShaders`) {
- if (`optionVar -q exportIncludeShaders`) {
- file -sh true;
- } else {
- file -sh false;
- }
- } // Else don't change the default value.
-
- if (($fileType == "mayaAscii" || $fileType == "mayaBinary")
- && (`optionVar -ex exportKeepOnlyRef`
- && `optionVar -q exportKeepOnlyRef`)) {
-
- // Then we really want to export it as a reference.
- string $cmd = ("file -type \""+$fileType+"\" ");
-
- string $clashName;
- if (`optionVar -exists exportOptionsUseRenamePrefix`) {
- int $userPrefix = `optionVar -q exportOptionsUseRenamePrefix`;
- if ($userPrefix && `optionVar -exists exportOptionsRenamePrefix`) {
- $clashName = `optionVar -q exportOptionsRenamePrefix`;
- }
- }
-
- if (size($clashName) == 0) {
- $clashName = pv_basename($theFile);
- }
-
- if (size($clashName) > 0) {
- if (`optionVar -q exportUseNamespacesDuringFileIO`) {
- $cmd = $cmd + "-namespace \""+$clashName+"\" ";
- } else {
- $cmd = $cmd + "-rpr \""+$clashName+"\" ";
- }
- }
-
- if ($gFileOptionsString != "") {
- $cmd = $cmd+"-options \""+$gFileOptionsString+"\" ";
- }
- $cmd = $cmd+"-er \""+$theFile+"\"";
- evalEcho($cmd);
- } else {
- file -op $gFileOptionsString -typ $fileType
- -es $theFile;
- }
- optionVar -sv defaultFileExportActiveType $fileType;
-
- // Restore the file -channels state, if it was changed.
- //
- if ($channelsValueChanged) {
- file -chn $oldChannelsValue;
- }
- } else { // It must be ExportAll.
- file -op $gFileOptionsString -typ $fileType -ea $theFile;
- optionVar -sv defaultFileExportAllType $fileType;
- }
- $status = true;
- }
- } else if ($gv_operationMode == "CreateReference") {
- // Create a new file to be used as a reference.
- $status = true;
- optionVar -sv defaultFileCreateReferenceType $fileType;
- file -op $gFileOptionsString -typ $fileType -nr $theFile;
- } else if ($fileExists) {
- if ($gv_operationMode == "Open") {
-
- $cmdString = "file -f ";
-
- if (size($gFileOptionsString) > 0) {
- $cmdString += "-options \""+$gFileOptionsString+"\" ";
- }
-
- // Only add the -executeScriptNodes flag for the negative
- // (non-default) case.
- //
- if (`optionVar -exists fileExecuteSN`) {
- if (!`optionVar -q fileExecuteSN`) {
- $cmdString += (" -esn false ");
- }
- }
-
- // Only add the -deferReference flag for the positive case.
- //
- if (`optionVar -exists fileLoadDeferRef`) {
- if (`optionVar -q fileLoadDeferRef`) {
- $cmdString += (" -lad true ");
- }
- }
-
- $cmdString += ( " -typ \""+$fileType+"\" -o \""+$theFile+"\";"+
- "addRecentFile(\"" + $theFile + "\", \"" +
- $fileType + "\")");
-
- $status = saveChanges($cmdString);
-
- } else if ($gv_operationMode == "Reference") {
- // Get the option information.
- string $cmd = "file -r -type \""+$fileType+"\" ";
-
- if (`optionVar -exists referenceOptionsGrouping`) {
- if (`optionVar -q referenceOptionsGrouping`) {
- $cmd = $cmd + "-gr ";
- }
- }
-
- string $clashName;
- if (`optionVar -exists referenceOptionsUseRenamePrefix`) {
- int $userPrefix = `optionVar -q referenceOptionsUseRenamePrefix`;
- if ($userPrefix && `optionVar -exists referenceOptionsRenamePrefix`) {
- $clashName = `optionVar -q referenceOptionsRenamePrefix`;
- }
- }
-
- if (size($clashName) == 0) {
- $clashName = pv_basename($theFile);
- }
-
- if (size($clashName) > 0) {
- if (`optionVar -q referenceUseNamespacesDuringFileIO`) {
- $cmd = $cmd + "-namespace \""+$clashName+"\" ";
- } else {
- $cmd = $cmd + "-rpr \""+$clashName+"\" ";
- }
- }
-
- if ($gFileOptionsString != "") {
- $cmd = $cmd+"-options \""+$gFileOptionsString+"\" ";
- }
-
- $cmd = $cmd + "\""+$theFile+"\"";
-
- evalEcho($cmd);
- $status = true;
- } else if ($gv_operationMode == "Import") {
- // Get the option information.
- string $cmd = "file -import -type \""+$fileType+"\" ";
-
- if (`optionVar -exists fileOptionsGrouping`) {
- if (`optionVar -q fileOptionsGrouping`) {
- $cmd = $cmd+"-gr ";
- }
- }
- if (`optionVar -exists fileOptionsRenameAll`) {
- if (`optionVar -q fileOptionsRenameAll`) {
- $cmd = $cmd+"-ra true ";
- }
- }
-
- string $clashName;
- if (`optionVar -exists fileOptionsUseRenamePrefix`) {
- int $userPrefix = `optionVar -q fileOptionsUseRenamePrefix`;
- if ($userPrefix && `optionVar -exists fileOptionsRenamePrefix`) {
- $clashName = `optionVar -q fileOptionsRenamePrefix`;
- }
- }
-
- if (size($clashName) == 0) {
- $clashName = pv_basename($theFile);
- }
-
- if (size($clashName) > 0) {
- if (`optionVar -q useNamespacesDuringFileIO`) {
- $cmd = $cmd + "-namespace \""+$clashName+"\" ";
- } else {
- $cmd = $cmd + "-rpr \""+$clashName+"\" ";
- }
- }
-
- if ($gFileOptionsString != "") {
- $cmd = $cmd+"-options \""+$gFileOptionsString+"\" ";
- }
- $cmd = $cmd+"\""+$theFile+"\"";
- evalEcho($cmd);
- $status = true;
- } else if ($gv_operationMode == "ReplaceReference") {
- // Get the option information.
- string $cmd = "file -loadReference \""+$gReplaceReferenceNode
- + "\" -type \""+$fileType+"\" ";
-
- if ($gFileOptionsString != "") {
- $cmd = $cmd+"-options \""+$gFileOptionsString+"\" ";
- }
-
- $cmd = $cmd + "\""+$theFile+"\"";
-
- evalEcho($cmd);
- $status = true;
- }
- } else {
- confirmDialog -m "File Does Not Exist. "
- -b "OK" -db "OK" -parent projectViewerWindow;
- }
- }
-
- return $status;
- }
-